#ifndef SPYTHREAD_H
#define SPYTHREAD_H

#include <QtCore>
#include <QtNetwork>
#include <QtSql>
#include <QCryptographicHash>
#include "spymon.h"

class SpyThread : public QThread
{
    Q_OBJECT

public:
    SpyThread(int);
    ~SpyThread();

    void run();

public slots:
    void readyRead();           // for reading data from the client
    void disconnect();          //
    void sendData(QString);     // for sending data to the client

signals:
    void log(int, QString);
    void finished();
    void error(QTcpSocket::SocketError socketError);

private:
    int sockDesc;
    QSslSocket *sslSock;
    quint16 blocksize;
    QString text, response;
    QString dbId;
    QSqlDatabase db;
    QString user, pass, tbl, opt;
    bool auth, admin;
    int user_id;

    void sdLog(int, QString);
    bool connectToDb();
    bool isAuth(QString, QString);
    bool isAdmin(QString);
    QString getUserId(QString);
    QString getAllMessages();
    QString getAllAcls();
    void addMsg(QString);
    void addAcl(QString, QString);
    void delAcl(QString, QString);
    void clrAcl(QString);
    void addUsr(QString, QString);
    void delUsr(QString);

};

#endif
